package com.jajahome.feature.scheme.adapter;

import android.content.Intent;
import android.graphics.Bitmap;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jajahome.R;
import com.jajahome.base.BaseRecyclerAdapter;
import com.jajahome.base.BaseRecyclerViewHolder;
import com.jajahome.feature.house.HouseSetListAct;
import com.jajahome.feature.scheme.SchemeDetailAct;
import com.jajahome.feature.scheme.SchemeListAct;
import com.jajahome.model.HouseListModel;
import com.jajahome.model.SchemeModel;
import com.jajahome.util.DensityUtil;
import com.jajahome.util.StringUtil;
import com.jajahome.widget.XCRoundRectImageView;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * 方案的adapter
 */
public class SchemeListAdapter extends BaseRecyclerAdapter<SchemeModel.DataBean.VrBean> {
    static int w; //宽度

    HouseListener listener;

    public void setListener(HouseListener listener) {
        this.listener = listener;
    }

    /**
     * @param viewHolder    基类ViewHolder,需要向下转型为对应的ViewHolder（example:MainRecyclerViewHolder mainRecyclerViewHolder=(MainRecyclerViewHolder) viewHolder;）
     * @param i             位置
     * @param mItemDataList 数据集合
     */
    @Override
    public void showData(BaseRecyclerViewHolder viewHolder, final int i, final List<SchemeModel.DataBean.VrBean> mItemDataList) {
        final ViewHolder holder = (ViewHolder) viewHolder;
        //取大图
        String url = mItemDataList.get(i).getVr_image().getThumb();
        //如果连接不为空 加载到bitmap  计算视图大小
        if (url != null && !StringUtil.isEmpty(url)) {
            Picasso.with(getContext())
                    .load(url)
                    .placeholder(R.mipmap.ic_bottom_background)
                    .into(holder.itemBannerImg);
        }
        holder.textView.setText(mItemDataList.get(i).getName());
        String brief = mItemDataList.get(i).getBrief();
        holder.textView2.setText(brief == null ? "" : brief);
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext, SchemeDetailAct.class);
                intent.putExtra(SchemeDetailAct.VR_BEAN, mItemDataList.get(i));
                mContext.startActivity(intent);

            }
        });
    }

    @Override
    public int getListLayoutId() {
        return R.layout.item_scheme_list;
    }

    /**
     * @param view item_frag_home_drag 的view
     * @return
     */
    @Override
    public BaseRecyclerViewHolder createViewHolder(View view) {
        w = (int) DensityUtil.getDisplayWidthDp(mContext);
        return new ViewHolder(view);
    }

    class ViewHolder extends BaseRecyclerViewHolder {
        ImageView itemBannerImg;
        TextView textView, textView2;

        public ViewHolder(View itemView) {
            super(itemView);
            itemBannerImg = (ImageView) findView(R.id.item_img);
            textView = (TextView) findView(R.id.textView);
            textView2 = (TextView) findView(R.id.textView2);
        }
    }


    public interface HouseListener {
        void onAddHouse(String id, ImageView colView);
    }

}

